<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>注册</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet" href="../AmazeUI-2.4.2/assets/css/amazeui.min.css"/>
    <link href="../css/dlstyle.css" rel="stylesheet" type="text/css">
    <script src="../AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="../AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
    <script src="js/pluges/vue/dist/vue.js"></script>
    <script src="js/pluges/axios/dist/axios.js"></script>
    <script src="js/base/common.js"></script>

</head>

<body>

<div class="login-boxtitle">
    <a href="home/demo.html"><img alt="" src="../images/logobig.png"/></a>
</div>

<div class="res-banner">
    <div class="res-main" id="register">
        <div class="login-banner-bg"><span></span><img src="../images/big.jpg"/></div>
        <div class="login-box">

            <div class="am-tabs" id="doc-my-tabs">
                <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                    <li class="am-active"><a @click="getImageCode" href="">邮箱注册</a></li>
                    <li><a @click="getImageCode" href="">手机号注册</a></li>
                    <button type="button" style="height: 25px" @click="goLogin">登录</button>
                </ul>

                <div class="am-tabs-bd">
                    <div class="am-tab-panel am-active">
                        <form method="post">

                            <div class="user-email">
                                <label for="email"><i class="am-icon-envelope-o"></i></label>
                                <input type="email" name="" v-model="emailRegisterForm.email" id="email"
                                       placeholder="请输入邮箱账号">
                            </div>
                            <div>
                            <input type="text" name="" v-model="emailRegisterForm.imageCodeValue"
                                   style="width: 180px;" placeholder="请输入图片验证码">
                            <img  @click="getImageCode" :src="imageCode"
                                 class="captcha-image-temp" alt="点击换图" title="点击换图"
                                 style="vertical-align: middle; cursor: pointer;">
                            </div>
                            <div class="verification">
                                <label for="code"><i class="am-icon-code-fork"></i></label>
                                <input type="tel" name="" style="width: 180px"
                                       v-model="emailRegisterFormSubmit.registerCode" placeholder="请输入验证码">
                                <button class="btn" @click="sendEmailCode" type="button">获取
                                </button>
                            </div>
                            <div class="user-pass">
                                <label for="password"><i class="am-icon-lock"></i></label>
                                <input type="password" name="" v-model="emailRegisterFormSubmit.password"  id="password" placeholder="设置密码">
                            </div>
                            <div class="user-pass">
                                <label for="passwordRepeat"><i class="am-icon-lock"></i></label>
                                <input type="password" name="" v-model="emailRegisterFormSubmit.charmPassword" id="passwordRepeat" placeholder="确认密码">
                            </div>

                        </form>

                        <div class="login-links">
                            <label for="reader-me">
                                <input id="reader-me" type="checkbox"> 点击表示您同意商城《服务协议》
                            </label>
                        </div>
                        <div class="am-cf">
                            <input type="submit" name="" @click="RegisterEmail" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl">
                        </div>
                    </div>

                    <div class="am-tab-panel">
                        <form method="post">
                            <div class="user-phone">
                                <label for="phone"><i class="am-icon-mobile-phone am-icon-md"></i></label>
                                <input type="tel" name="" v-model="phoneRegisterForm.phone" id="phone"
                                       placeholder="请输入手机号">
                            </div>
                            <div id="imgCode" class="user-phone">
                                <label for="imageCode"><i class="am-icon-check am-icon-sm"></i></label>
                                <input type="text" name="" v-model="phoneRegisterForm.imageCodeValue"
                                       style="width: 180px;" id="imageCode" placeholder="请输入图片验证码">
                                <img id="captcha-image-temp" @click="getImageCode" :src="imageCode"
                                     class="captcha-image-temp" alt="点击换图" title="点击换图"
                                     style="vertical-align: middle; cursor: pointer;">
                            </div>
                            <div class="verification">
                                <label for="code"><i class="am-icon-code-fork"></i></label>
                                <input type="tel" name="" style="width: 180px"
                                       v-model="phoneRegisterFormSubmit.registerCode" id="code" placeholder="请输入验证码">
                                <button class="btn" id="sendMobileCode" @click="sendMobileCode" type="button">获取
                                </button>
                            </div>

                            <div class="user-pass">
                                <label for="password"><i class="am-icon-lock"></i></label>
                                <input type="password" name="" v-model="phoneRegisterFormSubmit.password" id="password"
                                       placeholder="设置密码">
                            </div>
                            <div class="user-pass">
                                <label for="passwordRepeat"><i class="am-icon-lock"></i></label>
                                <input type="password" name="" v-model="phoneRegisterFormSubmit.charmPassword"
                                       id="passwordRepeat" placeholder="确认密码">
                            </div>
                        </form>
                        <div class="login-links">
                            <label for="reader-me">
                                <input id="reader-me" @click="readerMe" type="checkbox"> 点击表示您同意商城《服务协议》
                            </label>
                        </div>
                        <div class="am-cf">
                            <input type="submit" name="" @click="RegisterPhone" value="注册"
                                   class="am-btn am-btn-primary am-btn-sm am-fl">
                        </div>
                        <hr>
                    </div>

                    <script>
                        $(function () {
                            $('#doc-my-tabs').tabs();
                        })
                    </script>

                </div>
            </div>

        </div>
    </div>

    <div class="footer ">
        <div class="footer-hd ">
            <p>
                <a href="# ">恒望科技</a>
                <b>|</b>
                <a href="# ">商城首页</a>
                <b>|</b>
                <a href="# ">支付宝</a>
                <b>|</b>
                <a href="# ">物流</a>
            </p>
        </div>
        <div class="footer-bd ">
            <p>
                <a href="# ">关于恒望</a>
                <a href="# ">合作伙伴</a>
                <a href="# ">联系我们</a>
                <a href="# ">网站地图</a>
                <em>© 2015-2025 Hengwang.com 版权所有. 更多模板 <a href="http://www.cssmoban.com/" target="_blank" title="模板之家">模板之家</a>
                    - Collect from <a href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></em>
            </p>
        </div>
    </div>
</div>
</body>

<script type="text/javascript">
    new Vue({
        el: "#register",
        data: {

            emailRegisterForm:{
                email:"",
                imageCodeValue: "",
                imageCode: ""
            },
            imageCode: "",
            base64Prefix: "data:image/jpg;base64,",
            phoneRegisterForm: {
                imageCodeValue: "",
                phone: "",
                imageCode: "",
                type:"register"
            },
            emailRegisterFormSubmit:{
                email:"",
                password: "",
                charmPassword: "",
                registerCode: "",
                imageCodeValue: "",
                imageCode: ""
            },
            phoneRegisterFormSubmit: {
                charmPassword: "",
                password: "",
                registerCode: "",
                phone: "",
                imageCodeValue: "",
                imageCode: ""
            }
        },
        methods: {
            goLogin(){
                localStorage.removeItem("token");
                localStorage.removeItem("logininfo");
                location.href="http://bugtracker.itsource.cn/login.html";
            },
            sendEmailCode(event){
                // 判断输入的电话号不能为空
                if (!this.emailRegisterForm.email) {
                    alert("电话号不能为空");
                    return;
                }
                // 判断输入的验证码不能为空
                if (!this.emailRegisterForm.imageCodeValue) {
                    alert("验证码不能为空");
                    return;
                }
                // 判断输入的验证码长度是否为4
                if (this.emailRegisterForm.imageCodeValue.length != 4) {
                    alert("请输入图片所示验证码");
                    return;
                }
                var sendButton = $(event.target);
                // 将按钮变成不可点击
                sendButton.attr("disabled", true);
                // 获取imageCode
                this.emailRegisterForm.imageCode = localStorage.getItem("registerImageCodeKey");
                // 发送axios请求到后端
                this.$http.post("/verifyCode/emailCode", this.emailRegisterForm)
                    .then(result => {
                        console.log(result.data.success)
                        if (result.data.success) {
                            // 发起弹框
                            alert("邮件验证码已经发送至您的手机，请注意查收");
                            // 设置60秒
                            var time = 60;
                            // 设置定时器
                            var Interval = window.setInterval(function () {
                                time = time - 1;
                                sendButton.html(time + "重新发送");
                                if (time <= 0) {
                                    sendButton.html("重新发送");
                                    // 将按钮变成可点击
                                    sendButton.attr("disabled", false);
                                    // 消除定时器
                                    window.clearInterval(Interval)
                                }

                            }, 1000)
                        } else {
                            alert("邮件发送失败" + result.data.message);
                            // 将按钮变成可点击
                            sendButton.attr("disabled", false);
                        }
                    }).catch(result => {
                    alert("邮件发送失败" + result.data.message);
                })



            },

            readerMe() {

            },
            // 邮箱注册提交按钮
            RegisterEmail() {
                // 给emailRegisterFormSubmit对象中的email赋值
                this.emailRegisterFormSubmit.imageCodeValue = this.emailRegisterForm.imageCodeValue;
                this.emailRegisterFormSubmit.imageCode = localStorage.getItem("registerImageCodeKey");
                // 给emailRegisterFormSubmit对象中的email赋值
                this.emailRegisterFormSubmit.email = this.emailRegisterForm.email;
                // 发送axios请求
                this.$http.post("/user/register/email", this.emailRegisterFormSubmit)
                    .then(result => {
                        result = result.data;
                        if (result.success) {
                            localStorage.removeItem("token");
                            localStorage.removeItem("logininfo");
                            location.href = "login.html";
                        } else {
                            alert(result.message);
                        }
                    })
                    .catch(result => {
                        console.log(result);
                        alert("系统繁忙，请稍后重试！")
                    })
            },
            // 手机号注册提交按钮
            RegisterPhone() {
                // 给phoneRegisterFormSubmit对象中的phone赋值
                this.phoneRegisterFormSubmit.imageCodeValue = this.phoneRegisterForm.imageCodeValue;
                this.phoneRegisterFormSubmit.imageCode = localStorage.getItem("registerImageCodeKey");
                // 给phoneRegisterFormSubmit对象中的phone赋值
                this.phoneRegisterFormSubmit.phone = this.phoneRegisterForm.phone;
                // 发送axios请求
                this.$http.post("/user/register/phone", this.phoneRegisterFormSubmit)
                    .then(result => {
                        result = result.data;
                        if (result.success) {
                            localStorage.removeItem("token");
                            localStorage.removeItem("logininfo");
                            location.href = "login.html";
                        } else {
                            alert(result.message);
                        }
                    })
                    .catch(result => {
                        console.log(result);
                        alert("系统繁忙，请稍后重试！")
                    })
            },
            // 1.生成UUID的方法
            createUuid() {
                var s = [];
                var hexDigits = "0123456789abcdefghi";
                for (var i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
                s[8] = s[13] = s[18] = s[23] = "-";

                var uuid = s.join("");
                return uuid;
            },
            // 获取验证码的方法
            getImageCode() {
                // 查询localStroge中获取uuid
                var item = localStorage.getItem("registerImageCodeKey");
                // 判断localStroge中是否有key：registerImageCodeKey对应的值
                if (item == null || item === "") {
                    // 如果没有值 我们获取uuid
                    var s = this.createUuid();
                    // 将uuid保存到loacalStroage中
                    localStorage.setItem("registerImageCodeKey", s);
                }
                // 发送axios请求，传入uuid
                this.$http.get("/verifyCode/image/" + item).then(result => {
                    // 因为后端发送回来的是一个Base64编码的字符串（图片经过编码后形成的）所以我们需要拼接一个前缀才可以编译为图片，给图像验证码img标签的src赋值
                    this.imageCode = this.base64Prefix + result.data.result;
                })
            },
            // 点击获取按钮的点击事件
            sendMobileCode(event) {
                // 判断输入的电话号不能为空
                if (!this.phoneRegisterForm.phone) {
                    alert("电话号不能为空");
                    return;
                }
                // 判断输入的验证码不能为空
                if (!this.phoneRegisterForm.imageCodeValue) {
                    alert("验证码不能为空");
                    return;
                }
                // 判断输入的验证码长度是否为4
                if (this.phoneRegisterForm.imageCodeValue.length != 4) {
                    alert("请输入图片所示验证码");
                    return;
                }
                var sendButton = $(event.target);
                // 将按钮变成不可点击
                sendButton.attr("disabled", true);
                // 获取imageCode
                this.phoneRegisterForm.imageCode = localStorage.getItem("registerImageCodeKey");
                // 发送axios请求到后端
                this.$http.post("/verifyCode/smsCode", this.phoneRegisterForm)
                    .then(result => {
                        console.log(result.data.success)
                        if (result.data.success) {
                            // 发起弹框
                            alert("短信验证码已经发送至您的手机，请注意查收");
                            // 设置60秒
                            var time = 60;
                            // 设置定时器
                            var Interval = window.setInterval(function () {
                                time = time - 1;
                                sendButton.html(time + "重新发送");
                                if (time <= 0) {
                                    sendButton.html("重新发送");
                                    // 将按钮变成可点击
                                    sendButton.attr("disabled", false);
                                    // 消除定时器
                                    window.clearInterval(Interval)
                                }

                            }, 1000)
                        } else {
                            alert("短信发送失败" + result.data.message);
                            // 将按钮变成可点击
                            sendButton.attr("disabled", false);
                        }
                    }).catch(result => {
                    alert("短信发送失败" + result.data.message);
                })


            }
        },
        mounted() {
            this.getImageCode();
        }
    })
</script>
</html>